home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2011 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: castle.nando.net!news
  2. From: sekruege@nando.net (Steve Krueger)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: manipulating the stack in C
  5. Date: 26 Jan 1996 04:02:05 GMT
  6. Organization: News & Observer Public Access
  7. Message-ID: <4e9jnt$p5t@castle.nando.net>
  8. References: <4e8b20$lsq@newshost.lanl.gov>
  9. NNTP-Posting-Host: vyger410.nando.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=iso-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-NewsReader: Interworks_GRn 3.0 January 12, 1996
  14.  
  15. In article <4e8b20$lsq@newshost.lanl.gov> luke@raj2.tn.cornell.edu (Luke Emmert) writes:
  16. :   I'm currently writing an assembly function that takes a variable
  17. : number of arguments.  The last of the arguments is indicated by forcing
  18. : the stack to point at itself(a low probability occurence so I hope). 
  19. : The function is called from C code and I therefore need to get C to do
  20. : something weird with the stack.  Unfortunately, I need to make
  21. : assumptions about how the compiler will produce binary.
  22. :   The code looks like the following:
  23. : #define LAST_ARG (get_stack())
  24. :   foo( arg1, arg2, arg3, arg4, LAST_ARG );
  25. : where get_stack() simply returns the current
  26. : stack value:
  27. : _get_stack:
  28. :       move.l   a7,d0
  29. :       rts
  30. :   The problem arose last night, when I removed a printf() statement
  31. : that I used for debugging.  After disassembling the binary I found that
  32. : the stack was loaded in different ways in each case.  My program
  33. : assumes a particular way of loading the stack and that's why it failed.
  34. :   What I'd like to do is have something in-line that loads the current
  35. : stack value rather like
  36. :   move.l a7,(a7)
  37. : without having to use a function call.  I'm currently using SAS C v5.10
  38. : and I'm pretty sure that this cannot be done, but if any one has a
  39. : suggestion I would appreciate it.
  40.  
  41.  
  42. I would recommend that you don't attempt to do this, but if you really
  43. want to, you might try using the SAS/C function getreg(). For example:
  44.  
  45. #define LAST_ARG __builtin_getreg(REG_A7)
  46.  
  47.  
  48. The standard way to accomplish this kind of thing is to have the first
  49. argument indicate how many arguments will follow. 
  50.  
  51.  
  52. --                    |__  o\
  53.        ______         | W    \O
  54. __________  /__       |       H\_  
  55. __  ___/_  //_/       |      /-\   
  56. _(__  )_  ,<          |    /     \ 
  57. /____/ /_/|_|         |            
  58. sekruege@nando.net    |
  59.